clearvars -except Globaloption option

%% Saving parameter estimates to automatically update the paper
fID = fopen(['../../results/tables_main/Netherlands/TablePsi_pre1794.tex'], 'w');

%% Baseline Results
startdatenum = 1601;
enddatenum = 1794;
loaddata;

% Psi
Psichar = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'];
namebegin = '\\newcommand{\\preHollandPsi';
nameend1 = '}{%4.2f}\n';
nameend2 = '}{%4.0f}\n';

for ii = 1:N

    for jj = 1:N
        fprintf(fID, [namebegin Psichar(ii) Psichar(jj) nameend1], Psi(ii, jj));
    end

end

% Sig
Sigchar = Psichar;
snamebegin = '\\newcommand{\\PreHollandSig';
snameend1 = '}{%4.2f}\n';
snameend2 = '}{%4.0f}\n';

for ii = 1:N

    for jj = 1:N
        fprintf(fID, [snamebegin Sigchar(ii) Sigchar(jj) snameend1], 100 * Sig(ii, jj));
    end

end

taxrevgdp = tau;
spendgdp = g;
gdebt = debt;

% X2 mean
fprintf(fID, '\\newcommand{\\preHollandVarMeana}{%4.2f}\n', 100 * pi0);
fprintf(fID, '\\newcommand{\\preHollandVarMeanc}{%4.2f}\n', 100 * y0nom_10);
fprintf(fID, '\\newcommand{\\preHollandVarMeand}{%4.2f}\n', 100 * x0);
fprintf(fID, '\\newcommand{\\preHollandVarMeanh}{%4.2f}\n', 100 * mean(deltalogtau));
fprintf(fID, '\\newcommand{\\preHollandVarMeani}{%4.2f}\n', 100 * mean((taxrevgdp)));
fprintf(fID, '\\newcommand{\\preHollandVarMeanj}{%4.2f}\n', 100 * mean(deltalogg));
fprintf(fID, '\\newcommand{\\preHollandVarMeank}{%4.2f}\n', 100 * mean((spendgdp)));

load MAT/Netherland_cy_para_150_1601_1794.mat

fprintf(fID, '\\newcommand{\\preHollandkzerox}{%4.2f}\n', k0x);
fprintf(fID, '\\newcommand{\\preHollandkonex}{%4.2f}\n', k1x);
fprintf(fID, '\\newcommand{\\preHollandpdgdp}{%4.2f}\n', mean(exp(pxbar)));

fprintf(fID, '\\newcommand{\\preHollandsurplus}{%4.2f}\n', mean(taxrevgdp - spendgdp));
fprintf(fID, '\\newcommand{\\preHollandsurpluspct}{%4.2f}\n', 100 * mean(taxrevgdp - spendgdp));
fprintf(fID, '\\newcommand{\\preHollanddebtgdp}{%4.2f}\n', nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preHollanddebtgdppct}{%4.2f}\n', 100 * nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preHollandgdpreturn}{%4.2f}\n', 100 * mean(gdpreturn));


%with convenience yield
cy=0.015;
load MAT/Netherland_cy_para_150_1601_1794.mat

fprintf(fID, '\\newcommand{\\cygdpmeanHollandpre}{%4.2f}\n', mean(gdebt) * 2);
fprintf(fID, '\\newcommand{\\preHollandcorrpvscydebt}{%4.2f}\n', corr(gdebt, s'));
fprintf(fID, '\\newcommand{\\upperHollandprepct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\preHollandpvscytodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\smeanHollandcyprepct}{%4.2f}\n', mean(s) * 100);

fprintf(fID, '\\newcommand{\\preHollandsein}{%4.2f}\n', mean(gdebt) * cy * 100);
fprintf(fID, '\\newcommand{\\preHollandsum}{%4.2f}\n', mean(gdebt) * cy * 100 + mean(taxrevgdp - spendgdp) * 100);

% without convenience yield
load MAT/Netherland_para_30_fullsample.mat

fprintf(fID, '\\newcommand{\\preHollandmeansurpluszeroz}{%4.2f}\n', mean(upper));
fprintf(fID, '\\newcommand{\\preHollandmeansurpluszerozpct}{%4.2f}\n', 100 * mean(upper));
fprintf(fID, '\\newcommand{\\preHollandpvstodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\smeanHollandprepct}{%4.2f}\n', mean(s) * 100);

%% Close File
fclose(fID);
